package com.situ.company.score.service.impl;


import java.util.List;


import com.situ.company.employee.dao.IEmployeeDao;
import com.situ.company.employee.dao.impl.EmployeeDaoImpl;
import com.situ.company.employee.model.EmployeeModel;
import com.situ.company.project.dao.IProjectDao;
import com.situ.company.project.dao.impl.ProjectDaoImpl;
import com.situ.company.project.model.ProjectModel;
import com.situ.company.score.dao.IScoreDao;
import com.situ.company.score.dao.impl.ScoreDaoImpl;
import com.situ.company.score.model.ScoreModel;
import com.situ.company.score.service.IScoreService;

public class ScoreServiceImpl implements IScoreService {

	private IScoreDao dao = new ScoreDaoImpl();
	private IEmployeeDao employeeDao = new EmployeeDaoImpl();
	private IProjectDao projectDao = new ProjectDaoImpl();
	
	
	@Override
	public String update(ScoreModel model) {
		String codeEmp = model.getCodeEmp();
		 EmployeeModel empModel = new EmployeeModel();
		 empModel.setCode(codeEmp);
		 if(employeeDao.selectModel(empModel)==null)
		 	return "00";
		 String codePro = model.getCodePro();
		 ProjectModel proModel = new ProjectModel();
		 proModel.setCode(codePro);
		 if(projectDao.selectModel(proModel)==null)
		 	return"11";
		
		return dao.updateAll(model)+"";
	}
	
	
	
    public ScoreModel selectModel(ScoreModel model) {
    	
		return dao.selectModel(model);
	}
	
	
	@Override
	public List<ScoreModel> selectList(ScoreModel model) {
		String codeEmp = model.getCodeEmp();
		model.setCodeEmp(codeEmp==null? "%":"%"+codeEmp+"%");
		String codePro = model.getCodePro();
		model.setCodePro(codePro==null? "%":"%"+codePro+"%");
		List<ScoreModel> list = dao.selectList(model);
		
		return dao.selectList(model);
	}   
	
	@Override
	public Integer selectCount(ScoreModel model) {
		ScoreModel m1 = new ScoreModel();
		String codeEmp = model.getCodeEmp();
		m1.setCodeEmp(codeEmp==null? "%":"%"+codeEmp+"%");
		String codePro = model.getCodePro();
		m1.setCodePro(codePro==null? "%":"%"+codePro+"%");
		return dao.selectCount(m1);
		
	}
	
	 public String delete(ScoreModel model) {
			Integer res = dao.delete(model);
			return res ==null?null:res.toString();
			
		}
	 
	 public String insert(ScoreModel model) {
//			if(selectModel(model)==null) {
//				Integer res = dao.insert(model);
//				return res ==null?null:res.toString();
//			}
		 String codeEmp = model.getCodeEmp();
		 EmployeeModel empModel = new EmployeeModel();
		 empModel.setCode(codeEmp);
		 if(employeeDao.selectModel(empModel)==null)
		 	return "00";
		 String codePro = model.getCodePro();
		 ProjectModel proModel = new ProjectModel();
		 proModel.setCode(codePro);
		 if(projectDao.selectModel(proModel)==null)
		 	return"11";
		 
		 
			return dao.insert(model)+"";
		}
}
